package com.yanqu.road.server.cmd.activity.unionchest;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.UnionChestProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.unionchest.CrossUnionChestMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;


@Cmd(code = CrossProtocol.C2_UNIONCHEST_BOX_OPEN, desc = "开宝箱")
public class CrossUnionChestOpenCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionChestProto.CrossUnionChestOpenBoxReqMsg reqMsg = UnionChestProto.CrossUnionChestOpenBoxReqMsg.parseFrom(packet.getBytes());
        CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(), PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo()));
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_UNIONCHEST_BOX_OPEN_CROSS_BACK,
                CrossUnionChestMgr.openBox(reqMsg.getActivityId(), packet.getPlayerId(), reqMsg.getUserName(), reqMsg.getUnionId(), reqMsg.getReqMsg().getBoxId(), reqMsg.getReqMsg().getBoxIndex()));
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), pbMsg);
    }

    @Override
    public void sendData() {
    }
}
